/* 
 * File:   CombAlg.h
 * Author: mori
 *
 * Created on May 15, 2011, 9:34 PM
 */



#include "Grid.h"
#include "Parameters.h"
#include "Log.h"
#include "Constants.h"
#include <matrix.h>
#include "Psi.h"
#include "Error.h"
#include "GreenFunction.h"


#ifndef _NO_NAMESPACE
using namespace std;
using namespace math;
#define STD std
#else
#define STD
#endif

#ifndef _NO_TEMPLATE
typedef matrix<float> Matrix;
#else
typedef matrix Matrix;
#endif

#ifndef _NO_EXCEPTION
#define TRYBEGIN()	try {
#define CATCHERROR()	} catch (const STD::exception& e) { \
						cerr << "Error: " << e.what() << endl; }
#else
#define TRYBEGIN()
#define CATCHERROR()
#endif








extern Parameters* ppmts;
extern Log* plog;
extern Psi* psi;
extern Error* err;






class CombAlg {
  public:
      CombAlg(Grid* grid, Coils* coils, float** psi_bound, float** psi_ext, float** jphi, int n, int m);
  CombAlg(Grid* grid, float** psi_ext, int n, int m);
  void solve();
  void solve_sor();
  Matrix solve_sor2(Matrix m_bound, Matrix m_jphi);

  Matrix get_psipl_on_g(Matrix m_jphi);
  Matrix get_jphi(Matrix psipl);

  float A, D, E;
  float B(int i);
  float C(int i);
  float F(int i, int j);

  int size_n;
  int size_m;

  //area boundaries
  float left_r;
  float right_r;
  float up_z;
  float down_z;

  float psi_g, beta_pl, r0, alpha;
  float I;

  float h_r, h_z, h_r_2, h_z_2;
  float left_r_pl;
  float right_r_pl;
  float up_z_pl;
  float down_z_pl;

  int left_r_g, right_r_g, up_z_g, down_z_g;
  float omega;

  float e;


  Matrix bound;
  Matrix jphi_alt;
  Matrix psipl;
  Matrix psist;


  Matrix jphi_s;
  Matrix psipl_s;
};












